﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplicationTest
{
    public partial class Upload : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            UploadStatusLabel.Text = Request.QueryString["param"];
            LabelParam.Text = Request.ToString();
            //Response.Redirect(UploadStatusLabel.Text);  //
            if (!UploadStatusLabel.Text.Equals("")) Server.Transfer(UploadStatusLabel.Text);    //
        }

        protected void UploadButton_Click(object sender, EventArgs e)
        {
            // 设置文件保存目录
            string appPath = Request.PhysicalApplicationPath + @"Uploads\";
            if (!System.IO.Directory.Exists(appPath)) System.IO.Directory.CreateDirectory(appPath);

            // Before attempting to perform operations
            // on the file, verify that the FileUpload 
            // control contains a file.
            if (FileUpload1.HasFile)
            {
                // Get the name of the file to upload.
                String fileName = FileUpload1.FileName;

                // Append the name of the file to upload to the path.
                //savePath += fileName;
                string savePath = appPath + Server.HtmlEncode(FileUpload1.FileName);

                // Call the SaveAs method to save the 
                // uploaded file to the specified path.
                // This example does not perform all
                // the necessary error checking.               
                // If a file with the same name
                // already exists in the specified path,  
                // the uploaded file overwrites it.
                FileUpload1.SaveAs(savePath);

                // Notify the user of the name of the file
                // was saved under.
                UploadStatusLabel.Text = "Your file was saved as ->" + savePath;
            }
            else
            {
                // Notify the user that a file was not uploaded.
                UploadStatusLabel.Text = "You did not specify a file to upload.";
            }
        }
        
    }
}